<?php
namespace App\Api;

use PhalApi\Api;
use App\Domain\User as DomainUser;
/**
 * 用户模块接口服务
 */
class User extends Api {
    public function getRules() {
        return array(
            'login' => array(
                'username' => array('name' => 'username', 'require' => true, 'min' => 1, 'max' => 50, 'desc' => '用户名'),
                'password' => array('name' => 'password', 'require' => true, 'min' => 6, 'max' => 20, 'desc' => '密码'),
            ),
            'getList' => array(
                'page' => array('name' => 'page', 'type' => 'int', 'min' => 1, 'default' => 1, 'desc' => '第几页'),
                'size' => array('name' => 'size', 'type' => 'int', 'min' => 1, 'max' => 20, 'default' => 10, 'desc' => '分页数量'),
            ),
        );
    }
    /**
     * 登录接口
     * @desc 根据账号和密码进行登录操作
     * @return boolean is_login 是否登录成功
     * @return int user_id 用户ID
     */
    public function login() {
        $username = $this->username;   // 账号参数
        $password = $this->password;   // 密码参数
        // 更多其他操作……
        return array('is_login' => true, 'user_id' => 8);
    }


    public function test(){
        $model = new \App\Model\User();

        //插入
//        $data = array(
//            'name'=>"苏宁"
//        );
//        $rs = $model->insert($data);


//        //更新
//        $data = [
//            'age'=>12
//        ];
//        $rs = $model->update(1,$data);
//        print_r($rs);


//        $list =$model->getList($_GET['page'],$_GET['size']);

//        $list = $model->addOne();
//        return $list;


//        return $model->addUnique();
        $demo  = new \App\Model\Demo();
        $row = $demo->getNameById(3);
        var_dump($row);
        $row = $demo->getNameById(4);
        var_dump($row);
        $row = $demo->getNameById(2);
        var_dump($row);



    }

    public function getList(){
        $rs = [];
        $domain = new DomainUser();
        $rs['items'] = $domain->getList($this->page,$this->size);
        $list  = $domain->getList($this->page, $this->size);
        $rs['items'] = $list['items'];
        $rs['total'] = $list['total'];
        $rs['page'] = $this->page;
        $rs['size'] = $this->size;
//        \PhalApi\DI()->logger->debug('获取了一次',$rs);
        return $rs;
    }
} 
